package main

import (
	"fmt"
	"time"
)

func workJob(id int, jobs <-chan int, result chan<- int) {
	for job := range jobs {
		fmt.Println("worker", id, "processing job", job)
		time.Sleep(time.Second)
		result <- job * 2
	}
}

func main() {
	fmt.Println(time.Now())
	jobs := make(chan int, 3)
	result := make(chan int, 3)

	for i := 0; i < 3; i++ {
		go workJob(i, jobs, result)
	}

	for j := 0; j < 9; j++ {
		jobs <- j
	}
	close(jobs)

	for k := 0; k < 9; k++ {
		<-result
	}
	fmt.Println(time.Now())

}
